<?php


namespace App\Dao;

use App\Exception\BusinessException;
use App\Model\UserWithdraw;

class UserWithdrawDao extends AbstractDao
{
    public function where(array $where): \Hyperf\Database\Model\Builder
    {
        $builder = UserWithdraw::query();
        foreach ($where as $field => $value) {
            switch ($field) {
                case 'cooperative_ids':
                    $builder->whereIn('cooperative_id', $value);
                    break;
                case 'keywords':
                    $builder->whereHas('user', function ($query) use ($value) {
                        $query->where('nickname', 'like', '%' . $value . '%');
                        $query->orwhere('phone', $value);
                    });
                    break;
                default:
                    $builder->where($field, $value);
            }
        }
        return $builder;
    }
}